package org.wk.core.web.configure.async;

import java.util.concurrent.Executor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfigurer extends AsyncConfigurerSupport {
	@Autowired
    private ThreadPoolTaskExecutor asyncExecutor;
	
	@Override
    public Executor getAsyncExecutor() {
		return asyncExecutor;
    }
	
	@Bean
	public ThreadPoolTaskExecutor asyncExecutor() {
		ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
	    threadPool.setCorePoolSize(3);
	    threadPool.setMaxPoolSize(3);

	    threadPool.setWaitForTasksToCompleteOnShutdown(true);
	    threadPool.setAwaitTerminationSeconds(60 * 15);
        return threadPool;
	}
}
